package xyz.xiangyushui.controller.membership.reserveDesserts;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import xyz.xiangyushui.dao.user.member.CommodityReservableDao;
import xyz.xiangyushui.dao.user.member.ReservationHistoryDao;
import xyz.xiangyushui.javaBean.membership.Reservation;

/**
 * Servlet implementation class ReservationDelete
 */
@WebServlet("/member/reservation/delete")
public class ReservationDelete extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private ReservationHistoryDao rhd;
	private CommodityReservableDao crd;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ReservationDelete() {
        super();
        rhd=new ReservationHistoryDao();
        crd=new CommodityReservableDao();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id=request.getParameter("id");
		Reservation r=rhd.getReservation(Integer.parseInt(id));
		if(r!=null){
			rhd.deleteReservation(Integer.parseInt(id));
			crd.updateStock(r.getQuantity(), r.getDate_storeId(), r.getCommodityIdName());
		}
		request.getRequestDispatcher("/member/myReservation").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
